package servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.PollUserImpl;
import bean.PollUser;
public class loginServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8767999581281709013L;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost (request, response);
	}
	
	public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("GBK");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		
		PollUser user = new PollUser();
		user.setUsername(username);
		user.setPassword(password);

		PollUserImpl ck = new PollUserImpl();
		boolean bool = ck.checkuser(user);
		
		String forward;
		if (bool) {
			ck.setUserAttributes(user);
			forward = "success.jsp";
		} else {
			forward = "failure.jsp";
		}
		RequestDispatcher rd=request.getRequestDispatcher(forward);
		rd.forward(request, response);
	}
}
